package com.blrs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.blrs.common.annotation.RepeatSubmit;
import com.blrs.common.constant.HttpStatus;
import com.blrs.common.core.page.PageDomain;
import com.blrs.common.core.page.TableSupport;
import com.blrs.common.utils.page.PaginationUtil;
import com.blrs.domain.ContractManagementInfo;
import com.blrs.domain.ElectricSalesInfo;
import com.blrs.domain.vo.BusinessMainClassVo;
import com.blrs.domain.vo.ContractPaymentMethodVo;
import com.blrs.service.contract.IContractManagementInfoService;
import com.github.pagehelper.PageInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;

import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2023-11-30
 */
@RestController
@RequestMapping("/contractManagement/info")
public class ContractManagementInfoController extends BaseController
{
    @Autowired
    private IContractManagementInfoService contractManagementInfoService;

    /**
     * 查询【请填写功能名称】列表
     */
    //@PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContractManagementInfo contractManagementInfo)
    {
        startPage();
        List<ContractManagementInfo> list = contractManagementInfoService.selectContractManagementInfoList(contractManagementInfo);
        return getDataTable(list);
    }

    /**
     * 根据公司和电话 查询该联系人所有关联的合同
     * @param contractManagementInfo
     * @return
     */


    @GetMapping("/listReview")
    public TableDataInfo listReview(ContractManagementInfo contractManagementInfo, @RequestParam Integer pageNum, @RequestParam Integer pageSize)
    {
        //startPage();
        List<ContractManagementInfo> list = contractManagementInfoService.selectContractManagementReviewInfoList(contractManagementInfo);
        int start = (pageNum - 1) * pageSize;
        int end = Math.min(start + pageSize, list.size());
        List<ContractManagementInfo> contractManagementInfos = list.subList(start, end);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(contractManagementInfos);
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;
        //return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    //@PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractManagementInfo contractManagementInfo)
    {
        List<ContractManagementInfo> list = contractManagementInfoService.selectContractManagementInfoList(contractManagementInfo);
        ExcelUtil<ContractManagementInfo> util = new ExcelUtil<ContractManagementInfo>(ContractManagementInfo.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{contractId}")
    public AjaxResult getInfo(@PathVariable("contractId") String contractId)
    {
        return success(contractManagementInfoService.selectContractManagementInfoByContractId(contractId));
    }

    /**
     * 新增【请填写功能名称】
     */
    //@PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit(interval = 1000,message = "请勿重复提交！")
    public AjaxResult add(@RequestBody ContractManagementInfo contractManagementInfo)
    {
        return toAjax(contractManagementInfoService.insertContractManagementInfo(contractManagementInfo));
    }

    /**
     * 修改【请填写功能名称】
     */
    //@PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit(interval = 1000,message = "请勿重复提交！")
    public AjaxResult edit(@RequestBody ContractManagementInfo contractManagementInfo)
    {
        return toAjax(contractManagementInfoService.updateContractManagementInfo(contractManagementInfo));
    }

    /**
     * 删除【请填写功能名称】
     */
    //@PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contractIds}")
    public AjaxResult remove(@PathVariable String[] contractIds)
    {
        return toAjax(contractManagementInfoService.deleteContractManagementInfoByContractIds(contractIds));
    }

    @PostMapping("/saveContractPayment")
    public AjaxResult saveContractPayment(@RequestBody ContractPaymentMethodVo contractPaymentMethodVo) {
        return toAjax(contractManagementInfoService.saveContractPayment(contractPaymentMethodVo));
    }

    @PostMapping("/updateContractPayment")
    public AjaxResult updateContractPayment(@RequestBody ContractPaymentMethodVo contractPaymentMethodVo) {
        return toAjax(contractManagementInfoService.updateContractPayment(contractPaymentMethodVo));
    }

    @PostMapping("/editMainClass")
    public AjaxResult editMainClass(@RequestBody BusinessMainClassVo businessMainClassVo) {
        return toAjax(contractManagementInfoService.editMainClass(businessMainClassVo));
    }

    @PostMapping("/updateContractState")
    public AjaxResult updateContractState(@RequestBody ContractPaymentMethodVo contractPaymentMethodVo) {
        return toAjax(contractManagementInfoService.updateContractState(contractPaymentMethodVo));
    }

}
